Add auditable_type
and auditable_id
properties to Audit Model
#1025
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT: imported Carbon, apparently I missed that last time. Sorry 😬
Hi, Another addition to the Audit docblock to help with PHPStan type hinting.
This one is to add the
auditable_type
andauditable_id
columns used for theauditable
relation so they can be selcted, plucked, etc. The reason for this is an example below:In PHPStan levels 7 and above, this gives the following error:
Adding the properties to the Audit model resolves this. From looking at the migration stub, the morphable prefix for the auditable column cannot be changed so there shouldn't be a risk of these type hinted properties being incorrect.
User Properties
I haven't made the same change for the
user
relation. The reason why is that the config (and migration) allows for altering the prefix of the user morph column.laravel-auditing/config/audit.php
Lines 27 to 34 in c57fbec
laravel-auditing/database/migrations/audits.stub
Lines 21 to 24 in c57fbec
Therefore, trying to type hint them would be unreliable, as they can be changed.